package com.chenliang.service.impl;

import com.chenliang.dao.IRoledao;
import com.chenliang.domain.Permission;
import com.chenliang.domain.Role;
import com.chenliang.service.IRoleService;
import com.github.pagehelper.PageHelper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * @ProjectName: mavenSSM
 * @Package: com.chenliang.service.impl
 * 作用：
 */
@Service
public class RoleServiceImpl implements IRoleService {
    @Autowired
    private IRoledao roledao;

    @Override
    public List<Role> findAll(Integer page, Integer pageSize) {
        PageHelper.startPage(page, pageSize);
        return roledao.findAll();
    }

    @Override
    @Transactional
    public void addRole(Role role) throws Exception {

        roledao.addRole(role);
    }

    @Override
    public Role findById(String id) {
        return roledao.findById(id);
    }

    //    查询角色还没有的权限
    @Override
    public List<Permission> findRoleByPermission(String id) {
        return roledao.RolePermission(id);
    }

    //添加还没有的权限
    @Override
    public void addPermission(String roleId, String[] ids) {
        if (ids != null || ids.length != 0) {
            for (String id : ids) {
                roledao.addPermission(roleId, id);
            }

        }
    }
}
